package com.zd.controller;/**
 * @Description: DeliveryverificationController
 * @Author:pioneer
 * @Date: 2021-07-28
 * @Version:v1.0
 */

import com.zd.service.lnter.CostbreakdownzdServicelnter;
import com.zd.service.lnter.Deliveryverificationlnter;
import com.zd.service.lnter.FinancezdServicelnter;
import com.zzg.entity.Costbreakdown;
import com.zzg.entity.Finance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.DeflaterOutputStream;

/**
 * @Description: DeliveryverificationController 提货核销控制器
 * @Author:pioneer
 * @Date: 2021-07-28
 * @Version:v1.0
 */
@Controller
public class DeliveryverificationController {
    @Autowired
    private Deliveryverificationlnter deliveryverificationlnter;
    @Autowired
    private FinancezdServicelnter financezdServicelnter;
    @Autowired
    private CostbreakdownzdServicelnter costbreakdownzdServicelnter;

    /**
     * 查询签收列表的所有信息
     *
     * @param page  页码
     * @param limit 条目数
     * @return 签收map集合
     */
    @RequestMapping("queryDeliveryverification")
    @ResponseBody
    public Map<String, Object> queryDeliveryverification(int page, int limit) {
        System.out.println ("queryDeliveryverification进：page" + page + "\tlimit" + limit);
        Map<String, Object> map = new HashMap<> ();
        map.put ("code", "");
        map.put ("msg", "");
        map.put ("count", deliveryverificationlnter.queryDeliveryverification ().size ());
        map.put ("data", deliveryverificationlnter.pagingqueryDeliveryverification (page, limit));
        System.out.println (map);
        return map;
    }

    /**
     * 通过运单id得到费用明细
     * @param waybillid 运单id
     * @return 费用明细对象
     */
    @RequestMapping("getCostbreakdownByid")
    @ResponseBody
    public Costbreakdown getCostbreakdownByid(String waybillid) {
        System.out.println ("getCostbreakdownByid：进"+waybillid);
        Finance finance = financezdServicelnter.getFinanceByfinance (waybillid);
        Costbreakdown costbreakdown = costbreakdownzdServicelnter.getCostbreakdownByid (finance.getCostbreakdownId ());
        System.out.println ("costbreakdown"+costbreakdown);
        return costbreakdown;
    };

    @RequestMapping("updateVerification")
    public void updateVerification(Costbreakdown costbreakdown,HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        costbreakdown.setRealizefee (costbreakdown.getRealizefee ());
        int ser=costbreakdownzdServicelnter.updateCostbreakdown (costbreakdown);
        if(costbreakdown.getOwefee ()<=0){
            financezdServicelnter.updateFinancestate (costbreakdown.getCostbreakdownId (),"已结清");
        }
        if(ser>=0){
            out.write("修改成功");
        }else{
            out.write("修改失败");
        }
    }

    @RequestMapping("updateFinanceverification")
    public void updateFinanceverification(String waybillid,HttpServletResponse response) throws IOException {
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        Finance finance = financezdServicelnter.getFinanceByfinance (waybillid);
        int set=financezdServicelnter.updateFinanceverification (finance.getCostbreakdownId (),"已核销");
        if(set>=0){
            out.write("修改成功");
        }else{
            out.write("修改失败");
        }
    }
}


